package org.ling.xuan.rule;


import org.ling.xuan.common.CommonBizUtil;
import org.ling.xuan.config.SysConstant;
import org.ling.xuan.config.SystemProperties;
import org.ling.xuan.context.CheckChannelContext;
import org.ling.xuan.context.CheckPipelineContext;
import org.ling.xuan.entity.mo.CommonSetting;
import org.ling.xuan.entity.mo.ProjectSetting;
import org.ling.xuan.entity.mo.SvnCommitCheck;

public class SvnVersionCheckRule extends CheckRule<CheckChannelContext, CheckPipelineContext> {
    @Override
    public void check(CheckPipelineContext pipeContext, CheckChannelContext channelContext) {
        CommonSetting cs = pipeContext.getCommonSetting();
        ProjectSetting ps = pipeContext.getProjectSetting();
        SvnCommitCheck svnCommitCheck = CommonBizUtil.svnCheck(pipeContext.getFilePath(), cs, ps);
        if (svnCommitCheck.getCheckStatus() == 1) {
            pipeContext.success(svnCommitCheck.getMsg());
        } else if (svnCommitCheck.getCheckStatus() == 0) {
            pipeContext.error(svnCommitCheck.getMsg());
        } else {
            pipeContext.warn(svnCommitCheck.getMsg());
        }
    }

    @Override
    public boolean match(CheckPipelineContext pipeContext, CheckChannelContext channelContext) {
        return SystemProperties.isTrueDefaultTrue(SysConstant.checkSvnVersion);
    }

}
